package com.elong.businesstravel.protocol.city;


import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import com.android.support.jhf.utils.FileUtils;
import com.elong.businesstravel.entitys.City;
import com.elong.businesstravel.protocol.baseresponse.BaseELongJsonHttpResponse;

public class GetCityResponse extends BaseELongJsonHttpResponse {

	public City mCity = new City();
	public String responseString;

	@Override
	public void onSuccess(int statusCode, Header[] headers,
			JSONObject mainJsonObject) throws Throwable {
		
		responseString = mainJsonObject.toString();
		
		JSONObject responseJsonObject = mainJsonObject
				.getJSONObject("response");

		JSONArray hotJsonArray = responseJsonObject.getJSONArray("hot");
		for (int i = 0; i < hotJsonArray.length(); i++) {
			City city = new City();
			JSONObject hotItemJsonObject = hotJsonArray.getJSONObject(i);
			city.cityId = hotItemJsonObject.optString("cityid", "");
			city.cityName = hotItemJsonObject.optString("cityname", "");
			city.provinceId = hotItemJsonObject.optString("provinceid", "");
			city.firstCode = hotItemJsonObject.optString("firstcode", "");
			city.allCode = hotItemJsonObject.optString("allcode", "");
			city.sorts = hotItemJsonObject.optString("sorts", "");
			mCity.hotList.add(city);
		}

		JSONArray codeArray = responseJsonObject.getJSONArray("code");
		for (int i = 0; i < codeArray.length(); i++) {
			mCity.code.add(codeArray.getString(i));
		}

		JSONArray cityJsonArray = responseJsonObject.getJSONArray("city");
		for (int i = 0; i < cityJsonArray.length(); i++) {
			
			JSONArray cityItemJsonArray = cityJsonArray.getJSONArray(i);
			List<City> cityList = new ArrayList<City>();
			for (int j = 0; j < cityItemJsonArray.length(); j++) {
				City city = new City();
				JSONObject itemJsonObject = cityItemJsonArray.getJSONObject(j);
				city.cityId = itemJsonObject.optString("cityid", "");
				city.cityName = itemJsonObject.optString("cityname", "");
				city.provinceId = itemJsonObject.optString("provinceid", "");
				city.firstCode = itemJsonObject.optString("firstcode", "");
				city.allCode = itemJsonObject.optString("allcode", "");
				city.sorts = itemJsonObject.optString("sorts", "");
				cityList.add(city);
				
//				mCity.searchCityName.add(city.cityName);
//				mCity.searchCityPy.add(city.allCode);
				mCity.searchCityList.add(city);
			}
			
			mCity.cityList.add(cityList);
		}

	}

}
